﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Api.ContentProvider;
using System.Collections.Generic;
using System.Windows.Media.Imaging;

namespace DefaultContentProvider
{
    public class DefaultContentProvider : IContentProvider
    {
        private Dictionary<string, Func<string, UIElement>> Mappings { get; set; }

        public DefaultContentProvider()
        {
            this.Mappings = new Dictionary<string, Func<string, UIElement>>();

            this.Mappings.Add("text", value =>
            {
                var textBlock = new TextBlock();
                textBlock.Text = value;
                return textBlock;
            });

            this.Mappings.Add("link", value => 
                {
                    var hyperLink = new HyperlinkButton();
                    hyperLink.Content = value;
                    return hyperLink;
                });

            this.Mappings.Add("image", value =>
            {
                var image = new Image();
                image.Source = new BitmapImage(new Uri(value, UriKind.Absolute));
                return image;
            });
        }

        public Func<string, UIElement> GetItemsMapping(string itemType)
        {
            if (itemType == null)
            {
                throw new ArgumentNullException("itemType");
            }

            return this.Mappings[itemType];
        }

        public bool IsItemTypeSupported(string itemType)
        {
            if (this.Mappings.ContainsKey(itemType))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
